package cx3k.scheduler.objects.util;

import cx3k.scheduler.objects.Course;


public class CompareUtil {
	
	public static enum SemesterType {
		FALL_SEMESTER("FA", 1),
		SPRING_SEMESTER("SP", 2),
		WINTER_SESSION("WI", 3),
		SUMMER_SESSION_1("S1", 4),
		SUMMER_SESSION_2("S2", 4);
		
		private String code;
		private int order;
		
		private SemesterType(String code, int order){
			setCode(code);
			setOrder(order);
		}
		
		public String getCode(){
			return code;
		}
		
		public int getOrder(){
			return order;
		}
		
		private void setCode(String code){
			this.code = code;
		}
		
		private void setOrder(int order){
			this.order = order;
		}
		
		public boolean equals(String other){
			return this.getCode().equals(other);
		}

	}

	public static int compareYears(int year1, int year2){
		if(year1 < year2){
			return -1;
		} else if(year1 > year2){
			return 1;
		} else {
			return 0;
		}
	}
	
	public static boolean Equals(Course c1, Course c2)
	{
	if(c1.getCourseNum().equals(c2.getCourseNum()) && 
	c1.getDegreeProgram().equals(c2.getDegreeProgram()))return true;
	else return false;
	}
	
	public static int compareTerms(String term1, String term2){
		
		SemesterType typeTerm1 = null, typeTerm2 = null;
		
		for(SemesterType type : SemesterType.values()){
			if(type.equals(term1)){
				typeTerm1 = type;
			}
			
			if(type.equals(term2)){
				typeTerm2 = type;
			}
		}
		
		if(typeTerm1 == null && typeTerm2 == null){
			return 0;
		} else if(typeTerm1 == null){
			return 1;
		} else if(typeTerm2 == null){
			return -1;
		}
		
		if(typeTerm1.getOrder() < typeTerm2.getOrder()){
			return -1;
		} else if(typeTerm1.getOrder() > typeTerm2.getOrder()){
			return 1;
		} else {
			return 0;
		}
	}
}
